import 'package:flutter/material.dart';
import 'package:flutter_xlider/flutter_xlider.dart';
import 'package:flutter_soundmagus/util/util.dart';

enum VSliderStyle {
  gain,
  eq,
}

///垂直slider
class VSlider extends StatelessWidget {
  final double value;
  final Axis axis;
  final double? max;
  final double? min;
  final void Function(double value)? onChange;
  final double elevation;
  final FlutterSliderStep step;
  final VSliderStyle style;
  const VSlider({
    Key? key,
    required this.value,
    this.axis = Axis.horizontal,
    this.onChange,
    this.elevation = 3,
    this.max,
    this.min,
    this.step = const FlutterSliderStep(),
    this.style = VSliderStyle.gain,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget child = FlutterSlider(
      axis: axis,
      values: [value],
      max: max,
      min: min,
      rtl: axis == Axis.vertical,
      tooltip: FlutterSliderTooltip(disabled: true),
      step: step,
      handlerAnimation: FlutterSliderHandlerAnimation(scale: 1),
      handler: FlutterSliderHandler(
        decoration: BoxDecoration(),
        child: 'slider_thumb'.uiimgw(18.w),
      ),
      trackBar: FlutterSliderTrackBar(
        inactiveTrackBar: BoxDecoration(
          borderRadius: BorderRadius.circular(5.w),
          border: Border.all(
              color:
                  style == VSliderStyle.eq ? Colors.transparent : Colors.white),
          // color: Colors.grey[400],
        ),
        activeTrackBarHeight: 10.w,
        inactiveTrackBarHeight: 10.w,
        activeTrackBar: BoxDecoration(
            borderRadius: BorderRadius.circular(5.w),
            color: style == VSliderStyle.eq
                ? Colors.transparent
                : Theme.of(context).primaryColor),
      ),
      onDragging: (handlerIndex, lowerValue, upperValue) {
        onChange?.call(lowerValue);
      },
    );
    if (style == VSliderStyle.eq) {
      child = Stack(
        alignment: Alignment.center,
        children: [
          'eq_slider_v_kedu'.uiimg,
          child,
        ],
      );
    }
    return child;
  }
}
